/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.paroquiadegloria.ejc.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jadson
 */
public class ConnectionFactory {

    public static Connection con;
    private static String DRIVER = "com.mysql.jdbc.Driver";
    private static String URL = "jdbc:mysql://localhost/jadumco_ejc";
    private static String USER = "uejc";
    private static String PASS = "uejc00";

    @SuppressWarnings("unused")
    public static Connection getOrCreateConnection() {
        try {
            if (con == null || con.isClosed()) {
                Class.forName(DRIVER);
                con = DriverManager.getConnection(URL, USER, PASS);
            }
        } catch (SQLException e) {
            throw new RuntimeException("Erro ao tentar criar a conexao");
        } catch (Exception ex) {
            throw new RuntimeException("Erro ao obter o Driver");
        }
        return con;
    }

    public static void close() {
        try {
            if (con != null && !con.isClosed()) {
                con.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
